package cn.wolfcode.luowowo.mgrsite.web.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StatisVo;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.util.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

//@Component
public class RedisDataPersistenceJob {

    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyStatisVOService strategyStatisVOService;

    @Scheduled(cron = "0/10 * * * * ?")
    public void redisDataPersistence() {
        List<StrategyStatisVO> vos = strategyStatisVOService.listVo(RedisKeys.STRATEGY_STATIS_VO.join("*"));
        for (StrategyStatisVO vo : vos) {
            StatisVo statisVo = new StatisVo();
            BeanUtils.copyProperties(vo, statisVo);
            strategyDetailService.updateStatis(statisVo);
        }
    }
}
